import request from "@/util/request.ts";
import {
    AddOrUpdateUser,
    AllOrderStateResponseData,
    AllUserResponseData,
    DocumentTypeResponseData,
    OrderResponseData,
    PayResult,
    QrCode,
    SubmitOrder,
    UserInfoResponseData,
    UserOrderInfoResponseData,
    UserParams
} from "@/api/user/type.ts";

enum API {
    //获取订单号码接口
    SUBMITORDER_URL = '/order/orderInfo/auth/submitOrder/',

    //获取订单详情的数据
    GETORDERINFO_URL = '/order/orderInfo/auth/getOrderInfo/',

    //取消订单的预约
    OREDERCANCEL_URL = '/order/orderInfo/auth/cancelOrder/',

    //根据订单号生成微信支付二维码
    QRCODE_URL = '/order/weixin/createNative/',

    //查询订单支付的结果
    PAYRESULT_URL = '/order/weixin/queryPayStatus/',

    //获取当前账号的用户信息
    USERINFO_URL = '/user/auth/getUserInfo',

    //获取证件类型的接口信息
    CERTIFICATIONTYPE_URL = '/cmn/dict/findByDictCode/',

    //用户认证的接口地址
    USERCERTATION_URL = '/user/auth/userAuah',

    //获取用户挂号订单的接口地址
    USERORDERINFO_URL = '/order/orderInfo/auth/',

    //获取就诊人的信息
    ALLUSER_URL = '/user/patient/auth/findAll',

    //获取订单的状态
    ORDERSTATE_URL = '/order/orderInfo/auth/getStatusList',
    //获取城市的数据
    CITY_URL = '/cmn/dict/findByParentId/',

    //新增就诊人
    ADDUSER_URL = '/user/patient/auth/save',
    //修改就诊人信息接口
    UPDATEUSER_URL = '/user/patient/auth/update',
    //删除就诊人
    DELETEUSER_URL = '/user/patient/auth/remove/'
}

//提交订单
export const reqSubmitOrder = (hoscode: string, scheduleId: string, patientId: number) =>
    request.post<any, SubmitOrder>(API.SUBMITORDER_URL + `${hoscode}/${scheduleId}/${patientId}`)

//获取订单详情的数据
export const reqOrderInfo = (id: number) =>
    request.get<any, OrderResponseData>(API.GETORDERINFO_URL + `${id}`)

//取消订单的回调
export const reqOrderCancel = (orderId: string) =>
    request.get<any, any>(API.OREDERCANCEL_URL + `${orderId}`)

export const reqQrCode = (orderId: string) =>
    request.get<any, QrCode>(API.QRCODE_URL + `${orderId}`)

export const reqQueryPayState = (orderId: string) =>
    request.get<any, PayResult>(API.PAYRESULT_URL + `${orderId}`)

//获取当前用户信息的接口
export const reqUserInfo = () =>
    request.get<any, UserInfoResponseData>(API.USERINFO_URL)

export const reqCertificationType = (certification = 'CertificatesType') =>
    request.get<any, DocumentTypeResponseData>(API.CERTIFICATIONTYPE_URL + `${certification}`)

//用户认证接口
export const reqUserCertation = (data: UserParams) =>
    request.post<any, any>(API.USERCERTATION_URL, data)

//获取订单列表的接口
export const reqUserOrderInfo = (page: number, limit: number, patientId: string, orderStatus: string) =>
    request.get<any, UserOrderInfoResponseData>(API.USERORDERINFO_URL + `${page}/${limit}?patientId=${patientId}&orderStatus=${orderStatus}`)

//获取全部就诊人的信息
export const reqAllUser = () =>
    request.get<any, AllUserResponseData>(API.ALLUSER_URL)

//获取全部订单的状态的接口
export const reqOrderState = () =>
    request.get<any, AllOrderStateResponseData>(API.ORDERSTATE_URL)

export const reqCity = (parentId: string) =>
    request.get<any, any>(API.CITY_URL + `${parentId}`)

//新增与修改已有的就诊人接口方法
export const reqAddOrUpdateUser = (data: AddOrUpdateUser) => {
    if (data.id) {
        return request.put<any, any>(API.UPDATEUSER_URL, data)
    } else {
        return request.put<any, any>(API.ADDUSER_URL, data)
    }
}

//删除某一个就诊人的信息
export const reqDeleteUser = (id: number) =>
    request.delete<any, any>(API.DELETEUSER_URL + `${id}`)
